package com.example.controller;

import com.example.api.Result;
import com.example.configura.LogOperation;
import com.example.params.ClazzQueryParam;
import com.example.pojo.Clazz;
import com.example.service.ClazzService;
import com.example.vo.clazz.GetAllClazzInfoVo;
import com.example.vo.empvo.GetAllEmpInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    @GetMapping
    public Result<GetAllClazzInfoVo> getAllClazz(ClazzQueryParam clazzQueryParam){
        return Result.success(clazzService.getAllClazz(clazzQueryParam));

    }

    @DeleteMapping("/{id}")
    @LogOperation
    public Result<String> deleteClazzById(@PathVariable Integer id){
        return clazzService.deleteClazzById(id) ? Result.success("删除成功") : Result.error(0,"删除失败,该班级下关联有学生！");
    }

    @GetMapping("/{id}")
    public Result<Clazz> getClazzById(@PathVariable Integer id){
        return Result.success(clazzService.getClazzById(id));
    }
    @PutMapping
    @LogOperation
    public Result<String> updateClazz(@RequestBody Clazz clazz){
        return clazzService.updateClazz(clazz) ? Result.success("修改成功") : Result.error(0,"修改失败");
    }

    @PostMapping
    @LogOperation
    public Result<String> addClazz(@RequestBody Clazz clazz){
        return clazzService.addClazz(clazz) ? Result.success("添加成功") : Result.error(0,"添加失败");
    }

    @GetMapping("/list")
    public Result<List<Clazz>> getAllClazzList(){
        return Result.success(clazzService.getAll());
    }
}
